<template>
    <div class="app-container">
        <el-row :gutter="10">
            <el-col :span="12" :offset="6">
                <div style="text-align: center;margin-bottom: 30px;font-size: 16px">
                    位置{{ createStatus ? '新增' : '更新' }}
                </div>
                <el-form :model="positioningForm" ref="positioningForm" label-width="100px" :rules="positioningFormRules">
                    <el-row :gutter="10">
<!--                        <el-form-item label="所属主体" prop="enterpriseId" >-->
<!--                            <el-select v-model="positioningForm.enterpriseId" placeholder="请选择主体" style="width: 100%" @change="getInUserList">-->
<!--                                <el-option v-for="(item,index) in enterpriseDominantList" :key="index"  :value="item.ucId" :label="item.name"></el-option>-->
<!--                            </el-select>-->
<!--                        </el-form-item>-->
                          <el-form-item label="详细地址" prop="address">
                            <el-input  type="textarea"  :autosize="{ minRows: 3, maxRows: 5}"   maxlength="240"  show-word-limit v-model="positioningForm.address" placeholder="请输入详细地址" clearable></el-input>
                          </el-form-item>

                    </el-row>
                </el-form>
            </el-col>
        </el-row>
        <div slot="footer" style="text-align: center" class="dialog-footer">
            <el-button @click="cancelPositioning">取 消</el-button>
            <el-button :loading="addLoading" v-if="createStatus" type="primary" @click="createPositioning">创 建
            </el-button>
            <el-button :loading="addLoading" v-else type="primary" @click="updatePositioning">修 改</el-button>
        </div>
    </div>
</template>

<script>
import {getInPositioningVo,addInPositioning,updateInPositioning} from "@/api/positioning";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";
import {getInUserList} from "@/api/enterprise";


export default {
    name: "personWorkEdit",
    data() {
        return {
            positioningForm: {

            },
            addLoading: false,
            enterpriseDominantList:[],
            userList:[],
            positioningFormRules:{
                address: [{required: true, message: '详细地址不能为空', trigger: 'blur'}],
            },

        }
    },
    computed: {
        createStatus() {
            return this.$route.query.ucId == undefined
        },
        // enterPriseHidden(){
        //     let roleCode = this.$store.getters.roleCode;
        //     return roleCode=="XT-SUPER"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"
        // },
    },
    created() {
        // this.getInEnterpriseDominantList()
        if (!this.createStatus) {
            let ucId = this.$route.query.ucId
            this.getInPositioningVo(ucId)

        }
    },
    methods: {
        getInPositioningVo(val) {
            getInPositioningVo({ucId: val}).then(res => {
                this.positioningForm = res.data
                this.getInUserList(res.data.flagId)
            }).catch(error => {

            })
        },
        cancelPositioning() {
            window.history.back()
        },
        createPositioning() {
            this.addLoading = true
            this.$refs['positioningForm'].validate(valid => {
                if (valid) {
                    addInPositioning(this.positioningForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "添加定位成功"
                        })
                        this.cancelPositioning()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
        updatePositioning() {
            this.addLoading = true
            this.$refs['positioningForm'].validate(valid => {
                if (valid) {
                    updateInPositioning(this.positioningForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "更新个人工作成功"
                        })
                        this.cancelPositioning()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
        // getInEnterpriseDominantList(){
        //     getInEnterpriseDominantList({deleted:false}).then(res=>{
        //         this.enterpriseDominantList = res.data
        //     }).catch(error=>{
        //
        //     })
        // },
        // getInUserList(val){
        //     getInUserList({flagId:val,deleted:false}).then(res=>{
        //         this.userList = res.data
        //     }).catch(error=>{
        //
        //     })
        // },


    }

}
</script>
